﻿
Public Class AuthenticationValidator

    Shared Function GetLoggedInUser(p As Page) As UserType
        If (p.Session("LoggedUser") IsNot Nothing) Then
            Dim user As UserType = p.Session("LoggedUser")
            Return user
        Else
            p.Response.Redirect("AccessDeniedMsg.aspx")
            Return Nothing
        End If
    End Function

    Shared Function CheckIfAuthorized(p As Page, rightsName As String) As Boolean

        If (p.Session("LoggedUser") IsNot Nothing) Then
            Dim user As UserType = p.Session("LoggedUser")
            For Each r As String In user.Rights
                If r.ToLower = rightsName.ToLower Then
                    Return True
                End If
            Next
            Return False
        Else
            Return False
        End If
        Return False

    End Function

End Class

